Alexander Wirt: Cool things with grub2 and syslinux - booting floppy and iso images
From time to time I have to boot an iso or even a floppy. Unfortunately my X200 doesn't have a CD-Rom or a Floppy. Grub isn't able to boot isos and floppy images on its own, thats the point where syslinux comes into play: from version 4.x the syslinux memdisk driver is able to boot most iso and floppy images. The syslinux wiki has some details about the supported image types.
Yesterday I had to boot an iso image and instead of editing grub.cfg by hand I decided to create a snippet for grub.d to automate things. If you drop an .iso or an .img into the IMAGES path and run update-grub2 afterwards you get a nice boot entry that boots the floppy or iso image.
The only thing you have to do is to install syslinux and copy /usr/lib/syslinux/memdisk to /boot.
And here it comes:
#!/bin/sh
set -e
IMAGES=/boot/images
. /usr/lib/grub/grub-mkconfig_lib
if test -e /boot/memdisk ; then
MEMDISKPATH=$( make_system_path_relative_to_its_root "/boot/memdisk" )
echo "Found memdisk: $MEMDISKPATH" >&2
find $IMAGES -name "*.iso" -o -name '*.img' sort
while read image ; do
IMAGEPATH=$( make_system_path_relative_to_its_root "$image" )
case "$image" in
*.iso)
echo "Found iso image: $IMAGEPATH" >&2
cat << EOF
menuentry "Bootable ISO Image: $(basename $IMAGEPATH sed s/.img//)"
EOF
prepare_grub_to_access_device $ GRUB_DEVICE_BOOT sed -e "s/^/\t/"
cat << EOF
linux16 $MEMDISKPATH iso
initrd16 $IMAGEPATH
EOF
;;
*.img)
echo "Found floppy image: $IMAGEPATH" >&2
cat << EOF
menuentry "Bootable Floppy Image: $(basename $IMAGEPATH sed s/.img//)"
EOF
prepare_grub_to_access_device $ GRUB_DEVICE_BOOT sed -e "s/^/\t/"
cat << EOF
linux16 $MEMDISKPATH raw
initrd16 $IMAGEPATH
EOF
;;
esac
done
fi
P.S. I got the idea and some code snippets from several blog and wiki entries in the net and just added the iso part, so thats not all my code :)